package com.aionemu.gameserver.dataholders;

import gnu.trove.TIntObjectHashMap;

import java.util.List;

import javax.xml.bind.Unmarshaller;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

import com.aionemu.gameserver.model.templates.teleport.TeleportTemplate;

/**
 * This is a container holding and serving all {@link NpcTemplate} instances.<br>
 * Briefly: Every {@link Npc} instance represents some class of NPCs among which each have the same id, name, items,
 * statistics. Data for such NPC class is defined in {@link NpcTemplate} and is uniquely identified by npc id.
 * 
 * @author orz
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "teleports")
public class TeleportData
{
    @XmlElement(name = "teleport_template")
    protected List<TeleportTemplate> teleportTemplate;

	/** A map containing all trade list templates */
	@XmlTransient
	private final TIntObjectHashMap<TeleportTemplate>	listData	= new TIntObjectHashMap<TeleportTemplate>();

	void afterUnmarshal(Unmarshaller u, Object parent)
	{
		for (TeleportTemplate npc : teleportTemplate)
		{
			listData.put(npc.getTeleportId(), npc);
		}
	}

	public int size()
	{
		return listData.size();
	}

	/**
	 * Returns an {@link NpcTemplate} object with given id.
	 * 
	 * @param id
	 *            id of NPC
	 * @return NpcTemplate object containing data about NPC with that id.
	 */
	public TeleportTemplate getTeleporterTemplate(int id)
	{
		return listData.get(id);
	}

}
